package com.server.process.service;

import com.server.common.utils.IdWorker;
import com.server.domain.process.ProcessNode;
import com.server.domain.process.WorkFlow;
import com.server.process.dao.ProcessNodeDao;
import com.server.process.dao.WorkFlowDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProcessNodeService {
    @Autowired
    private ProcessNodeDao processNodeDao;
    @Autowired
    private IdWorker idWorker;

    /**
     * 构建新节点
     */
    public void add(ProcessNode processNode){
        String id = idWorker.nextId() + "";
        processNode.setId(id);
        processNodeDao.save(processNode);
    }
    /**
     * 更新节点
     */
    public void update(ProcessNode processNode) {
        // 根据id查询企业对象
        ProcessNode temp = processNodeDao.findById(processNode.getId()).get();
        // 修改属性值
        temp.setType(processNode.getType());
        temp.setX(processNode.getX());
        temp.setY(processNode.getY());
        temp.setText(processNode.getText());
        temp.setProperties(processNode.getProperties());
        // 更新企业
        processNodeDao.save(temp);
    }
    /**
     * 根据节点id查询节点
     */
    public ProcessNode findById(String id){
        return processNodeDao.findById(id).get();
    }
}
